package com.itxx.keyCase.Demo5;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    public static void main(String[] args) throws IOException {
        //1.创建ServerSocket对象
        ServerSocket ss = new ServerSocket(54421);
        //2.创建io流接受数据
        Socket accept = ss.accept();

        BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\develop\\workspace\\Advance_Code\\day15\\src\\com\\itxx\\keyCase\\server\\copy.jpg"));

        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
        }
        //4.接受完成 提醒客户端
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传完成");
        bw.newLine();
        bw.flush();

        //3.释放资源
        bos.close();
        accept.close();


    }
}
